package com.dounine.clouddisk360.parser.deserializer.captcha;

import java.io.IOException;

import org.apache.commons.lang3.StringUtils;
import org.apache.http.Consts;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.ResponseHandler;
import org.apache.http.util.EntityUtils;

import com.alibaba.fastjson.JSON;

public class CaptchaResponseHandle implements ResponseHandler<Captcha> {

	@Override
	public Captcha handleResponse(HttpResponse response) throws ClientProtocolException, IOException {
		HttpEntity entity = response.getEntity();
		String result = EntityUtils.toString(entity,Consts.UTF_8);
		return desializer(result);
	}
	
	public Captcha desializer(String result) {
		if (StringUtils.isNotBlank(result)) {
			return JSON.parseObject(result, Captcha.class);
		}
		return null;
	}

}
